﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KOPLibrary.DataManagement;
using KOPLibrary.Forms;
using KOPLibrary;


namespace KOP.Forms
{
    public partial class SendSmartEMailForm : Form
    {
        private AbstractData data = null;
        private string fileName;
        private object selectedWb = null;

        public SendSmartEMailForm()
        {
            InitializeComponent();
        }

        internal void Execute(Microsoft.Office.Interop.Word.Document document)
        {
            document.Save();
            fileName = document.FullName;
            ShowDialog();
        }

        private void ctlOutLook_Click(object sender, EventArgs e)
        {
            try
            {
                data = OutlookManager.RetreiveContacts();
                BindWordDocumentForm.ExecuteForm(data, true);
            }
            catch
            {
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (data == null)
                Util.ShowError("Lütfen önce veri seçiniz");
            else BindWordDocumentForm.ExecuteForm(data);
        }

        private void ctlGo_Click(object sender, EventArgs e)
        {
            if (data != null)
                new eMailForm().Execute(data, KOPLibrary.TemplateManagement.TemplateType.Word, Globals.AutoComplateAddIn.Application.ActiveDocument, "E-Posta Adresi");
            Close();
            new WordManager(Globals.AutoComplateAddIn.Application).OpenWordDocument(fileName, string.Empty);
        }

        private void ctlExcel_Click(object sender, EventArgs e)
        {
            selectedWb = ExcelManager.OpenForSelectData();
            ctlGetFromExcel.Visible = selectedWb != null;

        }

        private void ctlGetFromExcel_Click(object sender, EventArgs e)
        {
            try
            {
                AbstractData temp = ExcelManager.GetSelectedData(selectedWb);
                if (temp != null)
                    data = temp;
            }
            catch
            {
                ctlGetFromExcel.Visible = false;
            }
        }

        private void ctlClose_Click(object sender, EventArgs e)
        {

        }
    }
}
